public static class NetMsgHeadExtend
{
    static int ReadFixedInt32(this byte[] ptr,int offset)
    {
        return ptr[offset+3] | (ptr[offset+2] << 8) | (ptr[offset+1] << 16) | (ptr[offset] << 24);
    }
    static void WriteFixedInt32(this byte[] ptr,int offset,int value)
    {
        ptr[offset+3] = ((byte)value);
        ptr[offset+2] = ((byte)(value >> 8));
        ptr[offset+1] = ((byte)(value >> 16));
        ptr[offset] = ((byte)(value >> 24));
    }

    public static int getMsgId(this byte[] ptr)
    {
        return ReadFixedInt32(ptr, 4);
    }

    public static int getMsgLength(this byte[] ptr)
    {
        return ReadFixedInt32(ptr, 0);
    }

    public static void putMsgId(this byte[] bytes, int msgId)
    {
        bytes.WriteFixedInt32(4, msgId);
    }

    public static void putMsgLength(this byte[] bytes, int msgLength)
    {
        bytes.WriteFixedInt32(0, msgLength);
    }
}
